<%@ page language="java" pageEncoding="UTF-8"%>
<%@page import="com.adtech.adms.system.pojo.Feature"%>
<%@ taglib prefix="s" uri="/struts-tags"%>

<!--jquery validator显示错误信息的容器 -->
    <div class="serverErrorContainer" style="position:relative;">
        <div class="serverError">
        <ol>

        </ol>
        </div>
    
        <div class="container">
            <div class="searchButtonBox handleDiv" onclick="displayTable('handleDiv')">
            	<a href='javascript:void(0);' class="button switchOpen"  tabindex="-1" >
    			<div style="border:1px solid #96d0d2;border-bottom:0px;position:relative;float:right;cursor:pointer;">
    			<img id="handleDiv" src="../theme/default/images/main/search/search_switch_open_normal.png" style="position:absolute;top:6px">
    			<input type="button" style="margin-top:0px;width:16px;">
    			</div>
    			</a>
            </div>
            <div id="handleDiv_child" class="errorDIv" divAttend="attend">
                <ol>
                </ol>
            </div>
        </div>
    </div>
<!-- end -->

<form id="form" class="hForm treeForm" action="">

<table width="100%" cellspacing="0" cellpadding="0" style="padding:12px;">
<tbody>
<tr>
<td>
<table cellspacing="0" cellpadding="0" width="100%" height="20px" style="border:1px solid #c2e2eb;">
	<tr class="listviewHeader">
		<td class="tdTitle" colspan="2" id="detail_title">
			<s:hidden name="feature.id" id="featureId"></s:hidden>
			<s:hidden name="feature.parent.id"></s:hidden>
			<s:if test="feature.id!=null">
				编辑模块
			</s:if>
			<s:else>
				新建模块
			</s:else>
		</td>
	</tr>
</table>
</td>
</tr>

<tr><td>
<table cellpadding="0" cellspacing="0" width="100%" class="listviewTable" >
	<tr>
		<td id="txtmoduleNameshow" width="150px" class="listviewTD" style="text-align:right;">
			<font color="red">*</font>
			模块名称：
		</td>
		<td class="listviewContent">
			<s:textfield name="feature.name" cssClass="text" cssStyle="width:400px"></s:textfield>
		</td>
	</tr>
	<tr>
		<td id="txtmoduleCodeshow" class="listviewTD" style="text-align:right;">
			<font color="red">*</font>
			模块代码：
		</td>
		<td class="listviewContent">
			<s:textfield name="feature.code" id="code" cssClass="text" cssStyle="width:400px"></s:textfield>
		</td>
	</tr>
	<tr>
		<td id="txtmoduleOrderby" class="listviewTD" style="text-align:right;">
			<font color="red">*</font>
			排序编号：
		</td>
		<td class="listviewContent">
			<s:textfield name="feature.serialNumber" cssClass="text" cssStyle="width:100px"></s:textfield>
		</td>
       </tr>
	<s:if test="feature.id==null">
	<tr>
		<td id="txtmoduleNameshow" class="listviewTD" style="text-align:right;">
			是否为根节点：
		</td>
		<td class="listviewContent">
			<s:checkbox name="feature.root" id="feature_root"></s:checkbox>
		</td>
	</tr>
	</s:if>
	<s:if test="feature.parent.name==null">
	<tr id="parnet_text">
		<td id="txtmoduleNameshow" class="listviewTD" style="text-align:right;">
			上级模块：
		</td>
		<td class="listviewContent">
			<font id="parnet_name">${feature.parent.name }&nbsp;${edit }</font>
		</td>
	</tr>
	</s:if>
	<tr>
		<td id="txteditdeptnameshow" class="listviewTD" style="text-align:right;">
			入口类型：
		</td>
		<td class="listviewContent">
			<s:select list="#{'0':'按钮','1':'菜单','2':'链接' }" name="feature.entryType" style="width:100px"></s:select>
		</td>
	</tr>
	<tr>
		<td id="txtmoduleTarget" class="listviewTD" style="text-align:right;">
			目标：
		</td>
		<td class="listviewContent">
			<s:textfield name="feature.urlTarget" cssClass="text" cssStyle="width:100px"></s:textfield>
		</td>
	</tr>
	<tr>
		<td id="txteditdeptnameshow" class="listviewTD" style="text-align:right;">
			风格：
		</td>
		<td class="listviewContent">
			<s:textfield name="feature.classes" cssClass="text" cssStyle="width:100px"></s:textfield>
		</td>
	</tr>
	<tr>
		<td id="txtmoduleUrl" class="listviewTD" style="text-align:right;">
			URL：
		</td>
		<td class="listviewContent">
			<s:textfield name="feature.url" cssClass="text" cssStyle="width:500px"></s:textfield>
		</td>
	</tr>
	<tr>
		<td id="txtmoduleRemark" class="listviewTD" style="text-align:right;">
			说明：
		</td>
		<td class="listviewContent">
			<s:textarea name="feature.comments" cssClass="text" cssStyle="width:100px" rows="5"></s:textarea>
		</td>
	</tr>
</table>
</td></tr></table>
<div>
	
	<div class="topo_button">
			<a href="#" class="button" tabindex="-1"><input id="save_button" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" type="button" value="保存"></a>
	</div>
</div>
</form>

<script>
$(document).ready(function(){
	
	var container = $('div.container');
	// validate the form when it is submitted
	var validator = $("#form").validate({
		submitHandler: function(form) {
			return false;
		},
		errorContainer: container,
		errorLabelContainer: $("ol", container),
		wrapper: 'li',
		meta: "validate",
		rules: {
		     "feature.name":{
		      required: true, 
		      maxlength:100
		     },
		     "feature.code":{
			      required: true, 
			      maxlength:100,
			      remote: {
				      	url: '<s:url value="/feature/check"/>',
				      	type: 'post',
				      	data: {
				      		id : function() {
				      			return $('#featureId').val();
				      		}
				      	}
				  }
			  },
			  "feature.serialNumber":{
			      required: true,
			      digits:true
			  }
	    },
	    messages:{
	    	"feature.name":{
	    		required: "模块名称是必需的"
	    	},
	    	"feature.code":{
	    		required: "模块编码是必需的",
	    		remote: jQuery.format("功能模块不能重复！")
	    	},
	    	"feature.serialNumber":{
	    		required: "排序编号是必需的",
	    		digits: "排序编号必须为整数"
	    	}
	    }
	});
	
	
	
	
	
	
	$("#save_button").bind('click',function(){
		if(!validator.form()){
			return;
		}
		selectedNode =	treeObject.getSelectedNodes()[0];
		$.adAjax({
			type : "post",
			url : '<s:url value="/feature/save"/>',
			data:$('#form').serialize(),
			success : function(){
				if(selectedNode == null){
					$("#featureTree").zTree(setting);
				}else{
					var nodes=treeObject.getNodes();
					if(nodes.length<=0||$("#feature_root").attr("checked")){
						document.location.href="<s:url value="/feature/frame"/>";
						return;
					}
	                selectedNode.isParent =true;
					treeObject.updateNode(selectedNode, true);                                
					<s:if test="%{feature.id!=null}">
						treeObject.reAsyncChildNodes(selectedNode.parentNode, "refresh");
					</s:if>
					<s:else>
						treeObject.reAsyncChildNodes(selectedNode, "refresh");
					</s:else>
					treeObject.selectNode (selectedNode,true);
					$('#detail_panel').load('<s:url value="/feature/detail"/>?id='+ selectedNode.id);
				}
				
			}
		});
	});
	
	<s:if test="%{feature.id == null}">
	$('#parnet_name').text(treeObject.getSelectedNode().name);
	</s:if>
	
	$("#feature_root").bind('click',function(){
		if(this.checked){
			$('#parnet_text').hide();
		}else{
			$('#parnet_text').show();
		}
	});
	contentLayout();
});

function contentLayout(){
	$(".tempDiv").css("height",window.document.body.clientHeight-34-28);
	$(".content_c").css("height",window.document.body.clientHeight-$(".serverErrorContainer").height()-46-34-28);
	if($.browser.msie&&($.browser.version == "6.0")){
		$(".content_c").css("width",window.document.body.clientWidth-5);
	}
	//$(".serverErrorContainer").css("width",window.document.body.clientWidth);
}

$(window).resize(function(){
	$(".tempDiv").css("height",window.document.body.clientHeight-34-28);
	$(".content_c").css("height",window.document.body.clientHeight-$(".serverErrorContainer").height()-46-34-28);
	if($.browser.msie&&($.browser.version == "6.0")){
		$(".content_c").css("width",window.document.body.clientWidth-5);
	}
	$(".serverErrorContainer").css("width",window.document.body.clientWidth);
});
</script>